//
//  PwrdSdkApi.cpp
//
//  Created by galileoliu on 2019/1/10.
//


#include "PwrdSdkApi.hpp"

#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID && CC_TARGET_PLATFORM != CC_PLATFORM_IOS)

static std::string s_versionInfo = "1.0.0.1";

void PwrdSdkApi::setRemoteVersionInfo(std::string versionInfoStr)
{
    s_versionInfo = versionInfoStr;
}

std::string PwrdSdkApi::getRemoteVersionInfo()
{
    return s_versionInfo;
}

std::string PwrdSdkApi::getRemoteAppVersion()
{
    std::string ret = "1.0.0";
    auto idx = s_versionInfo.find_last_of(".");
    ret = s_versionInfo.substr(0, idx);
    return ret;
}

std::string PwrdSdkApi::getRemoteResourceVersion()
{
    std::string ret = "1";
    auto idx = s_versionInfo.find_last_of(".");
    ret = s_versionInfo.substr(idx+1);
    return ret;
}

void PwrdSdkApi::jumpToAppShop(){
    
}

bool PwrdSdkApi::isReview(){
    return false;
}

bool PwrdSdkApi::checkPermissions(){
    return true;
}
void PwrdSdkApi::requestPermissions(){
    
}

void PwrdSdkApi::goAppSetting(){
    
}

void PwrdSdkApi::wanmeiTrackEvent(const char* data){
    
}
void PwrdSdkApi::wanmeiGameEvent(const char* eventName, int stateIndex, const char* url, const char* errorMsg){
    
}
void PwrdSdkApi::setSDKLanguage(const char* language){
    
}
#endif

std::vector<std::string> PwrdSdkApi::getCdnList(){
    std::vector<std::string> ret;
    cocos2d::Configuration* configuration = cocos2d::Configuration::getInstance();
    const cocos2d::Value& cdnUrlValue = configuration->getValue("CDNUpdateUrl");
    std::string strCdn = cdnUrlValue.asString();
    while (true) {
        auto index = strCdn.find(";");
        std::string subStr = strCdn.substr(0, index);
        if (!subStr.empty()) {
            // Append automatically "/"
            if (subStr[subStr.size() - 1] != '/') {
                subStr.append("/");
            }
            ret.push_back(subStr);
        }
        strCdn.erase(0, index + 1);
        if (index == -1) {
            break;
        }
    }
    return ret;
}
